<template>
  <div class="songsList">
    <ul>
      <li 
        v-for="(value,index) in SongListObj.musicList" 
        :key="index" 
        @click="GetSongId(index)">
        <span class="circle">
          <span :class="listindex==index?'dbline':'triangle'"></span>
        </span>
        <!-- 歌曲名称 -->
        {{value.name}}
        <!-- mv播放按钮 -->
        <span
          class="mvPlayBtn"
          v-if="value.mvid!=0"
          @click="ShowMv(value.mvid)"
          @click.stop
          title="Mv">
        </span>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "SongList",
  props: {
      SongListObj:{
          type:Object,
          required:true
      },
  },
  data() {
    return {
      songId: 0,
      songUrl: "",
      songIndex: -1,
      //歌单用索引值
      listindex: -1,
      //音频播放状态
      audioisplay: false,
    };
  },
  watch:{
      'SongListObj.audioisplay'(v){
         this.audioisplay=v
         this.changeLeftImg()
      }
  },
  methods: {
    GetSongId(v) {
      this.songIndex = v;
      this.songId = this.SongListObj.musicList[v].id;
      this.$emit("ClickedSongId", this.songId);
      this.GetSongUrl();
    //点击歌单歌曲可切换播放状态
    //this.$store.commit("changeSongState",!this.$store.state.global.songState);
    },

    GetSongUrl() {
      let o = {
        id: this.songId,
      };
      this.$api.SongUrl(o).then((res) => {
          if (res.data[0].url == null) {
            alert("当前歌曲无版权");
          } else {
            this.songUrl = res.data[0].url;
            this.$emit("ClickedSongUrl", this.songUrl);
            this.$emit('isClick')
            this.changeLeftImg();
          }
      }).catch(() => {});
    },
    //歌单左侧按钮形状控制
    changeLeftImg() {
      if (this.audioisplay) {
        this.listindex = this.songIndex;
      } else {
        this.listindex = -1;
      }
    },
    ShowMv(v) {
      this.$emit("MvId", v);
    },
  },
};
</script>
<style scoped>
/* 歌单列表 */
.songsList {
  height: 100%;
  width: 250px;
  border-right: 1px solid #ccc;
  padding: 30px;
  overflow: hidden;
}

.songsList ul {
  width: 125%;
  height: 110%;
  overflow-y: scroll;
}

.songsList ul li {
  width: 100%;
  height: 30px;
  line-height: 30px;
  padding-left: 30px;
  position: relative;
}

/* 歌曲播放按钮 */
.songsList li .circle {
  display: inline-block;
  position: absolute;
  top: 5px;
  left: 5px;
  width: 20px;
  height: 20px;
  background-color: #fff;
  border: 2px solid #f00;
  border-radius: 50%;
}

.songsList li .circle .triangle {
  display: inline-block;
  position: absolute;
  top: 2px;
  left: 5px;
  border-left: 8px solid #f00;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-radius: 10px;
}

.songsList li .circle .dbline {
  display: inline-block;
  position: absolute;
  top: 2px;
  left: 3px;
  border: 3px solid #f00;
  width: 10px;
  height: 11px;
  border-top: none;
  border-bottom: none;
}

/* 歌单背景 */
.songsList ul li:nth-child(2n + 1) {
  background-color: #eee;
}

/* 歌曲覆盖事件 */
.songsList ul li:hover {
  background-color: #eee;
}

/* mv播放按钮 */
.songsList .mvPlayBtn {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 40px;
  height: 40px;
  background: url(../../assets/table.png) no-repeat 11px -46px/83px 65px;
}
</style>